from selenium import webdriver
class woniu():

    def __init__(self):
        self.op=webdriver.Firefox()
        self.op.get("http://192.168.2.159:8080/woniusales")
    def login(self,username,password,verifycode):
        self.op.find_element_by_id("username").clear()
        self.op.find_element_by_id("username").send_keys(username)
        self.op.find_element_by_id("password").clear()
        self.op.find_element_by_id("password").send_keys(password)
        self.op.find_element_by_id("verifycode").clear()
        self.op.find_element_by_id("verifycode").send_keys(verifycode)
        # self.op.find_element_by_id("verifycode").send_keys("0000")
        self.op.find_element_by_xpath('//div[6]/button').click()
    def test(self,username,password,verifycode,expect):
        self.login(username,password,verifycode)
        # t=self.op.switch_to.alert.text
        try:
            t=self.op.find_element_by_class_name("bootbox-body").text
            if t==expect:
                print("ok")
            else:
                print("ko")
            self.op.find_element_by_xpath('/html/body/div[6]/div/div/div[3]/button').click()
        except:
            print("success")

if __name__ == '__main__':
    s=woniu()
    with open("..\\webdriver\\data.txt") as f:
        p=f.readlines()
        for line in p:
            username=line.strip().split(',')[0]
            password=line.strip().split(',')[1]
            verifycode=line.strip().split(',')[2]
            expect = line.strip().split(',')[3]
            s.test(username,password,verifycode,expect)


